namespace string_utils
{
	inline string format(const char* fmt, ...)
	{
		assert(fmt);

		const uint32 BUFFER_SIZE = 1024;
		char buf[BUFFER_SIZE];

		va_list args;
		va_start(args, fmt);
		vsnprintf_s(buf, sizeof(buf), sizeof(buf), fmt, args);
		va_end(args);

		return buf;
	}

	inline void split(const char* text, std::vector<string>& result, const char* delimiter)
	{
		assert(text);
		assert(delimiter);

		result.clear();

		uint size = strlen(text) + 1;
		char* text_copy = static_cast<char*>(alloca(size));
		memcpy_s(text_copy, size, text, size);

		char* next_token = nullptr;
		char* token = nullptr;
		token = strtok_s(text_copy, delimiter, &next_token);
		while (token)
		{
			result.push_back(token);
			token = strtok_s(nullptr, delimiter, &next_token);
		}
	}

	inline bool from_string(const char* text, int& result)
	{
		return sscanf_s(text, "%i", &result) == 1;
	}

	inline bool from_string(const char* text, uint& result)
	{
		return sscanf_s(text, "%u", &result) == 1;
	}

	inline bool from_string(const char* text, float& result)
	{
		return sscanf_s(text, "%f", &result) == 1;
	}

	inline string to_string(int val)
	{
		return format("%i", val);
	}

	inline string to_string(uint val)
	{
		return format("%u", val);
	}

	inline string to_string(float val)
	{
		return format("%f", val);
	}

	inline bool is_digit(char symbol)
	{
		return symbol >= '0' && symbol <= '9';
	}

	inline bool is_alpha(char symbol)
	{
		return symbol >= 'a' && symbol <= 'z' || symbol >= 'A' && symbol <= 'Z';
	}

	inline bool is_punctuation(char symbol)
	{
		return symbol == '.' || symbol == ',' || symbol == ':' || symbol == '\\' || symbol == '`' ||
			symbol ==';' || symbol == '!' || symbol == '?';
	}

	inline bool is_printable(char symbol)
	{
		return symbol >= ' ' && symbol <= '~';
	}
}